App({
  globalData: {
    theme: 'dark' // 默认深色主题
  },

  onLaunch: function () {
    // 小程序启动时的初始化逻辑
    console.log("环境监测系统小程序启动");
    
    // 初始化主题
    this.initTheme();
  },

  // 初始化主题
  initTheme: function() {
    const savedTheme = wx.getStorageSync('theme') || 'dark';
    this.globalData.theme = savedTheme;
    this.applyGlobalTheme(savedTheme);
  },

  // 应用全局主题
  applyGlobalTheme: function(theme) {
    this.globalData.theme = theme;
    
    // 设置导航栏颜色
    if (theme === 'light') {
      wx.setNavigationBarColor({
        frontColor: '#000000',
        backgroundColor: '#ffffff'
      });
    } else {
      wx.setNavigationBarColor({
        frontColor: '#ffffff',
        backgroundColor: '#0f172a'
      });
    }
  },

  // 切换主题
  switchTheme: function(theme) {
    this.globalData.theme = theme;
    wx.setStorageSync('theme', theme);
    this.applyGlobalTheme(theme);
  }
});